import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/Login')
  },
  {
    path: '/layout',
    name: 'Layout',
    component: () => import('@/views/layout/Layout'),
    children: [{
        path: 'userAdd',
        name: 'UserAdd',
        component: () => import('@/views/layout/user/UserAdd'),
        meta: {
          name: '用户添加'
        }
      },
      {
        path: 'userList',
        name: 'UserList',
        component: () => import('@/views/layout/user/UserList'),
        meta: {
          name: '用户列表'
        }
      }, {
        path: 'articleList',
        name: 'ArticleList',
        component: () => import('@/views/layout/article/ArticleList'),
        meta: {
          name: '文章列表'
        }
      },
      {
        path: 'articlePublished',
        name: 'ArticlePublished',
        component: () => import('@/views/layout/article/ArticlePublished'),
        meta: {
          name: '文章发布'
        }
      }, {
        path: 'programAdd',
        name: 'ProgramAdd',
        component: () => import('@/views/layout/program/ProgramAdd'),
        meta: {
          name: '栏目添加'
        }
      }, {
        path: 'programList',
        name: 'ProgramList',
        component: () => import('@/views/layout/program/ProgramList'),
        meta: {
          name: '栏目列表'
        }
      }, {
        path: '/',
        redirect: '/layout/userAdd'
      }
    ]
  },
  {
    path: '/',
    redirect: '/layout'
  }
]


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

const isflag = true;
router.beforeEach((to, from, next) => {
  if (to.path == '/layout' && !isflag) {
    router.push('/login');
  } else {
    next();
  }
})

export default router

/*
  配置路由的步骤
    1. 下载并导入 vue-router
    2. 使用 Vue.use(VueRouter)
    3. 配置路由规则。
    4. 在new VueRouter({}) 实例身上使用配置的路由规则
*/
